//
//  SearchBar.swift
//  uiKit-demo
//
//  Created by 陈澎 on 2025/1/6.
//
import UIKit
public class SearchBarUI:UIViewController {
    func render(_ self: AnyObject){
        let searchBar = UISearchBar()
//        searchBar.frame = CGRect(x: 20, y: 120, width: 280, height: 30)
        searchBar.searchBarStyle = UISearchBar.Style.prominent
        searchBar.placeholder = "请输入搜索内容"
//        self.view?.addSubview(searchBar)
        
        searchBar.barTintColor = .red
        
        let changeBtn = UIButton()
        changeBtn.setTitle("切换", for: .normal)
        changeBtn.backgroundColor =  UIColor.red
        changeBtn.setTitleColor(.white, for: .normal)
        changeBtn.translatesAutoresizingMaskIntoConstraints = false
        
//        changeBtn.frame = CGRect(x: searchBar., y: <#T##CGFloat#>, width: <#T##CGFloat#>, height: <#T##CGFloat#>)
        let stackView = UIStackView(arrangedSubviews: [searchBar, changeBtn])
        stackView.axis = .horizontal
        stackView.spacing = 20
        stackView.distribution = .fillEqually
        self.view?.addSubview(stackView)
        // 禁用自动调整约束
        stackView.translatesAutoresizingMaskIntoConstraints = false
        
        // 设置 StackView 的约束
        NSLayoutConstraint.activate([
            stackView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 50),
            stackView.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
            stackView.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: -20),
            changeBtn.widthAnchor.constraint(equalToConstant: 50),
            changeBtn.heightAnchor.constraint(equalToConstant: 30)
        ])

    }
}
